import { genURL, injectScript } from "./utils.js";
import { red, blue, green } from "./logger.js";
export default function (packageName, { type = "script" } = {}) {
    const [_, name, version = "latest", path] =
        packageName.match(/(.*)@?([\d\.]*)(.*)/);
    const url = genURL({ name, path, version });
    switch (type) {
        case "module":
            return import(url).then((res) => {
                console.log(
                    `➡ %c ${packageName} %cIt's a es-module script. You could get %c${Object.keys(
                        res
                    ).join()} %c from the module.`,
                    blue,
                    green,
                    red,
                    green
                );
                return res;
            });
        case "script":
        default:
            return injectScript(url).then((newVar) => {
                console.log(
                    `➡ %c ${packageName} %cWe had loaded the script. Maybe you could get %c ${newVar.join()}  %c in window`,
                    blue,
                    green,
                    red,
                    green
                );
                return newVar;
            });
    }
}
